#include "projectordata.h"
#include "projectortype.h"


namespace Projector
{
ProjectorData* ProjectorData::sInstance = 0;
QMutex* ProjectorData::sMutex = new QMutex();

ProjectorData::ProjectorData()
{
    this->mProjectors       = new QMap<QString, Projector*>();
}

ProjectorData::~ProjectorData()
{
    delete mProjectors;
    mProjectors = NULL;
}

ProjectorData* ProjectorData::GetInstance()
{
    sMutex->lock();
    if(!sInstance)
    {
        sInstance = new ProjectorData();
    }
    sMutex->unlock();
    return sInstance;
}

void ProjectorData::AddProjector(Projector* projector)
{
    GetInstance()->mProjectors->insert(projector->GetName(), projector);
    return;
}

void ProjectorData::AddProjectorType(ProjectorType* projectorType)
{
    GetInstance()->mProjectorTypes->insert(projectorType->GetName(), projectorType);
    return;
}

Projector const* ProjectorData::GetProjector(int index) const
{
    return GetInstance()->GetProjectors()->value(GetInstance()->GetProjectors()->keys().at(index));
}

Projector const* ProjectorData::GetProjector(QString& projName) const
{
    return GetInstance()->GetProjectors()->value(projName);
}

QMap<QString, Projector*> const* ProjectorData::GetProjectors() const
{
    return mProjectors;
}



}
